package AliDiepPR.hWriting;

import AliDiepPR.Util.*;

import AliDiepPR.Util.ImageProcessing;
import AliDiepPR.hWriting.R;
import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.widget.TextView;

public class Test extends Activity {
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.test);

		TextView view = (TextView) findViewById(R.id.tvTest);
		// View viewImage = (View) findViewById(R.id.viewImage);

		String str = "";
		WriteView writeView = HWritingActivity.writeView;
		writeView.setDrawingCacheEnabled(true);
		Bitmap image = writeView.getImage();
		// viewImage.setBackgroundDrawable(new BitmapDrawable(image));
		/*
		 * double temp[] = ImageProcessing.flattenIntMatrix(ImageTransformer
		 * .getScaledImage(20, 20, ImageTransformer
		 * .getMinimalImageMatrix(getBinaryImage(image)))); float input[] = new
		 * float[temp.length]; for (int i = 0; i < temp.length; i++) input[i] =
		 * (float) temp[i];
		 */
		int input[][] = AliDiepPR.Util.ImageProcessing.getZone(
				new Size(16, 16), image);
		// str += String.valueOf(input[0][0])+' '+String.valueOf(input[0][1]);

		for (int i = 0; i < input[0][0]; i++) {
			for (int j = 0; j < input[0][1]; j++)
				str += input[0][2 + i * input[0][1] + j];
			str += "\n";
		}

		view.setText(str);

		writeView.resetView();
		writeView.setDrawingCacheEnabled(false);
	}

	private int[][] getBinaryImage(Bitmap bitmap) {
		int width = bitmap.getWidth();
		int height = bitmap.getHeight();
		int[][] result = new int[height][width];
		for (int i = 0; i < height; i++) {
			for (int j = 0; j < width; j++) {
				int temp = bitmap.getPixel(j, i);
				temp = ImageProcessing.grayScale(temp);
				if (temp >= 250) {
					result[i][j] = 0;
				} else {
					result[i][j] = 1;
				}
			}
		}
		return result;
	}
}
